﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConstAll;

namespace FileSystem
{
    public class NormalFileWriter
    {
        public static void WriteTextToFile(string textContent)
        {
            string folder = Const.OUTPUT_FILE_FOLDER;
            string fileName = Const.OUTPUT_FILE_NAME;

            WriteTextToFile(textContent, folder, fileName);
        }

        public static void WriteTextToRandomNameFile(string textContent)
        {
            string fileName = System.IO.Path.GetRandomFileName();
            string folder = Const.OUTPUT_FILE_FOLDER;

            WriteTextToFile(textContent, folder, fileName);
        }

        public static void WriteTextToFile(string textContent, string fileFolder, string fileName)
        {
            System.IO.Directory.CreateDirectory(fileFolder);
            string filePath = System.IO.Path.Combine(fileFolder, fileName);

            if (!System.IO.File.Exists(filePath))
            {
                using (System.IO.FileStream fs = System.IO.File.Create(filePath))
                {
                    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fs))
                    {
                        writer.WriteLine(textContent);
                    }
                }
            }
            else
            {
                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(filePath, true))
                {
                    writer.WriteLine(textContent);
                }
            }
        }
    }
}
